-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert to SocketPool #198
Conversation
646d60c
to
35fd193
Compare
Looks good! Config: code...import time
import os
import traceback
import board
import busio
import digitalio
import os
import adafruit_connection_manager
import adafruit_requests
from adafruit_esp32spi.adafruit_esp32spi import ESP_SPIcontrol
URLS = ("http://wifitest.adafruit.com/testwifi/index.html", "https://httpbin.org/get")
def get_requests(radio):
# this allows creating multiple requests sessions for multiple devices
pool = adafruit_connection_manager.get_radio_socketpool(radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
requests = adafruit_requests.Session(pool, ssl_context)
return requests
def connect_esp(radio):
while not radio.is_connected:
try:
radio.connect_AP(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))
except Exception as ex:
traceback.print_exception(ex, ex, ex.__traceback__)
ipv4_str = radio.pretty_ip(radio.ip_address)
return ipv4_str
spi = board.SPI()
esp32_cs = digitalio.DigitalInOut(board.A0)
esp32_reset = digitalio.DigitalInOut(board.A1)
esp32_ready = digitalio.DigitalInOut(board.A2)
radio = ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, debug=False)
requests_esp = get_requests(radio)
while True:
print(f'{"="*25}')
for url in URLS:
print(f'{"-"*25}')
print(f"Fetching from {url} via ESP32SPI {connect_esp(radio)} ", end="")
with requests_esp.get(url) as resp:
print(f'{resp.status_code} {resp.reason.decode()}')
time.sleep(5) |
This kind of bypasses https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/main/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py. Do you see that as being supplanted by ConnectionManager eventually? It does have functionality CM does not. I was interested in replacing the |
To me so far, Connection Manager is all about sockets, and it's shaping up to be a very simple API, versatile for single- and multiple-network configurations. I seem to recall a discussion about whether it should take on additional features like wifi connection, but don't remember the conclusion. I couldn't find anything in In The Weeds from this year. I have some concern about CM getting too big with disparate features. |
@dhalbert I would love to take out the rest of secrets. If you help me come up with the right path, I take it and run |
@anecdata Thanks for that perspective. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-tested with adafruit/Adafruit_CircuitPython_ConnectionManager#11 (review). Good to go pending any others with code review
Looks good, but is this an incompatible change? If so, then we need to update Guide code right away after merging this. |
Only if they aren't using ConnectionManager. Here's the only guide we need to update: https://github.com/search?q=repo%3Aadafruit%2FAdafruit_Learning_System_Guides+adafruit_esp32spi_socket&type=code |
OK, let's merge this, and then if you can make a PR to the Learn Guide repo, that would be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updating ConnectionManager at same time.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 8.0.0 from 7.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#198 from justmobilize/convert-to-socketpool Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 7.0.0 from 6.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#159 from justmobilize/convert-to-socketpool Updating https://github.com/adafruit/Adafruit_CircuitPython_ConnectionManager to 2.0.0 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#11 from justmobilize/esp32spi-and-wiznet5k-socketpool Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
For use with: adafruit/Adafruit_CircuitPython_ConnectionManager#11
Converting from the old
adafruit_esp32spi/adafruit_esp32spi_socket.py
toadafruit_esp32spi/adafruit_esp32spi_socketpool.py
to removeset_interface
and work more like a built-in SocketPool.This also allows one to use multiple ESP32SPI boards at the same time.
General example:
or with the new
ConnectionManager